<?php


namespace App\Service\RiskCheck;


use App\Model\Dao\RiskRuleCollectionDao;
use App\Utils\CustomUtils;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Utils\ApplicationContext;

/**
 * Class ChannelRiskCheckService
 * 通道风控
 *
 * @package App\Service\RiskCheck
 */
class ChannelRiskCheckService implements RiskCheckInterface {

    /**
     * @var RiskRuleCollectionDao
     * @Inject()
     */
    protected $RiskRuleCollectionDao;

    public function handle ($params) {

        $channelNo = $params['channelNo'];
        $params    = $params['data'];

        CustomUtils::xzxDebug([
            "channelNo" => $channelNo,
            "params"    => $params,
        ]);

        // 获取规则列表
        $ruleList = $this->RiskRuleCollectionDao->readChannelRuleList($channelNo);

        CustomUtils::xzxDebug("通道风控规则列表", $ruleList);

        // 通用风控检查
        return ApplicationContext::getContainer()->get(CommonRiskCheckService::class)->handle($params, $ruleList);
    }

    public function clearCache ($channelNo) {
        $this->RiskRuleCollectionDao->clearChannelRuleList($channelNo);
    }
}
